package edu.zut.cs.software.perfect.base.service.impl;

import java.io.Serializable;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

import edu.zut.cs.software.perfect.base.dao.GenericDao;
import edu.zut.cs.software.perfect.base.domain.BaseEntity;
import edu.zut.cs.software.perfect.base.service.GenericManager;

/**
 * @ClassName GenericManagerImpl
 * @Description TODO
 * @Author xiaoyingzi
 * @Date 2020年3月17日 下午5:27:28
 * @Version 1.0
 */
@Transactional
public class GenericManagerImpl<PK extends Serializable, T extends BaseEntity<PK>> implements GenericManager<PK, T> {

	protected GenericDao<T, PK> dao;
	
	
	public T findById(PK courseId) {
		return this.dao.findById(courseId).get();
	}

	
	public void delete(PK courseId) {
		this.dao.deleteById(courseId);
	}

	@Override
	public void deleteAll() {
		this.dao.deleteAll();
		
	}

	
	public Iterable<T> findAll() {
		return this.dao.findAll();
	}

	
	public Page<T> findAll(Pageable page) {
		Page<T> result = this.dao.findAll(page);
		return result;
	}

	
	public Iterable<T> save(Iterable<T> entities) {
		return this.dao.saveAll(entities);
	}

	
	public T save(T entity) {
		T data = this.dao.save(entity);
		return data;
	}

	@Override
	public long count() {
		return this.dao.count();
	}

	

	



}
